package com.esb.utils;

import java.util.Properties;

public final class ConfigUtils {

	private static volatile Properties PROPERTIES;
	private static Properties getProperties() {
        if (PROPERTIES == null) {
            synchronized (ConfigUtils.class) {
                if (PROPERTIES == null) {
                    PROPERTIES = loadProperties(Constants.ESB_PROPERTIES_FILE);
                }
            }
        }
        return PROPERTIES;
    }
	
	public static Properties loadProperties(String filePath) {
        Properties properties = new Properties();
        try {
            properties.load(ConfigUtils.class.getClassLoader().getResourceAsStream(filePath));
        } catch (Throwable e) {
        	e.printStackTrace();
            return null;
        }
        return properties;
    }

	public static String getProperty(String key, String defaultValue) {
        return getProperties().getProperty(key, defaultValue);
    }
	
	public static int getProperty(String key, int defaultValue) {
        return Integer.valueOf(getProperty(key, String.valueOf(defaultValue)));
    }
}
